// pages/me/dynamic-change/dynamic-change.js
var initChart = null
var initChart2 = null

Page({
  /**
   * 页面的初始数据
   */
  data: {
    onInitChart(F2, config) {
      initChart = new F2.Chart(config);
      initChart.source([], {
        followerNum: {
          min: 0,
          formatter(ivalue) {
            return (ivalue/10000).toFixed(1) + (parseInt(ivalue/10000) > 0 ? 'w' : '');
          }
        },
        date: {
          range: [ 0, 1 ],
          tickCount: 5
        }
      });
      initChart.tooltip({
        showCrosshairs: true,
        showItemMarker: false,
        onShow: function onShow(ev) {
          const items = ev.items;
          items[0].name = '白细胞';
          items[0].value = items[0].value;
        }
      });
      initChart.area().color('#275CBB').position('date*followerNum');
      initChart.line().color('#275CBB').position('date*followerNum');
      initChart.point().color('#275CBB').position('date*followerNum');
      initChart.render();
      // 注意：需要把chart return 出来
      return initChart;
    },
    onInitChart2(F2, config) {
      initChart2 = new F2.Chart(config);
      initChart2.source([], {
        followerNum: {
          min: 0,
          formatter(ivalue) {
            return (ivalue/10000).toFixed(1) + (parseInt(ivalue/10000) > 0 ? 'w' : '');
          }
        },
        date: {
          range: [ 0, 1 ],
          tickCount: 5
        }
      });
      initChart2.tooltip({
        showCrosshairs: true,
        showItemMarker: false,
        onShow: function onShow(ev) {
          const items = ev.items;
          items[0].name = '白细胞';
          items[0].value = items[0].value;
        }
      });
      initChart2.area().color('#275CBB').position('date*followerNum');
      initChart2.line().color('#275CBB').position('date*followerNum');
      initChart2.point().color('#275CBB').position('date*followerNum');
      initChart2.render();
      // 注意：需要把chart return 出来
      return initChart2;
    }
  },
  back() {
    wx.navigateBack({
      delta: 1
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    const data = [
      {
          "date": "02.18",
          "incrNum": -224,
          "followerNum": 449813
      },
      {
          "date": "02.19",
          "incrNum": 1725,
          "followerNum": 451538
      },
      {
          "date": "02.20",
          "incrNum": -267,
          "followerNum": 451271
      },
      {
          "date": "02.21",
          "incrNum": 995,
          "followerNum": 452266
      },
      {
          "date": "02.22",
          "incrNum": 563,
          "followerNum": 452829
      },
      {
          "date": "02.23",
          "incrNum": -263,
          "followerNum": 452566
      },
      {
          "date": "02.24",
          "incrNum": -269,
          "followerNum": 452297
      },
      {
          "date": "02.25",
          "incrNum": 579,
          "followerNum": 452876
      },
      {
          "date": "02.26",
          "incrNum": -172,
          "followerNum": 452704
      },
      {
          "date": "02.27",
          "incrNum": 173,
          "followerNum": 452877
      },
      {
          "date": "02.28",
          "incrNum": 41505,
          "followerNum": 494382
      },
      {
          "date": "03.01",
          "incrNum": -236,
          "followerNum": 494146
      }
    ]

    setTimeout(() => {
      initChart.changeData(data)
      initChart2.changeData(data)
    }, 1000)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})